| Total Complexity | 2 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Injectable } from '@nestjs/common'; |
||
| 5 | |||
| 6 | @Injectable() |
||
| 7 | export class FileUploadS3Adapter implements IFileUpload { |
||
| 8 | constructor( |
||
| 9 | private readonly configService: ConfigService, |
||
| 10 | private readonly s3Factory: S3Factory |
||
| 11 | ) {} |
||
| 12 | |||
| 13 | public getEndPoint(filePath: string): Promise<string> { |
||
| 14 | const bucket = this.configService.get<string>('STORAGE_BUCKET'); |
||
| 15 | |||
| 16 | const s3Api = this.s3Factory.create(); |
||
| 17 | |||
| 18 | const s3Params = { |
||
| 19 | Bucket: bucket, |
||
| 20 | Key: filePath, |
||
| 21 | Expires: 600, |
||
| 22 | ContentType: 'application/octet-stream' |
||
| 23 | }; |
||
| 24 | |||
| 25 | return new Promise<string>((resolve, reject) => { |
||
| 26 | s3Api.getSignedUrl('putObject', s3Params, (err, data) => { |
||
| 27 | if (err) { |
||
| 28 | reject(err); |
||
| 29 | } |
||
| 30 | resolve(data); |
||
| 31 | }); |
||
| 35 |